package com.cloudcc.mobile.view.schedule;

import android.os.Bundle;
import android.view.MotionEvent;

import com.cloudcc.cloudframe.bus.EventEngine;
import com.cloudcc.cloudframe.bus.IEventLife;
import com.cloudcc.mobile.event.isleft;
import com.cloudcc.mobile.event.isshow;
import com.cloudcc.mobile.view.base.BaseFragmentActivity;
import com.litesuits.android.log.Log;

import de.greenrobot.event.EventBus;

public class ScheduleMainActivity extends BaseFragmentActivity implements IEventLife{
	public static ScheduleMainActivity instance = null;
	@Override
	public void init(Bundle savedInstanceState) {
		super.init(savedInstanceState);
		instance = this;
		register();
		ScheduleMainFragment scheduleMainFragment = new ScheduleMainFragment();
		scheduleMainFragment.setArguments(getIntent().getExtras());
		getSupportFragmentManager().beginTransaction()
				.add(getContainerId(), scheduleMainFragment).commit();
	}

	float x1 = 0;
	float x2 = 0;
	float y1 = 0;
	float y2 = 0;
	isshow issh = new isshow();
	isleft isle = new isleft();

	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			// 当手指按下的时候
			Log.d("zuobiao", "(" + x1 + "," + y1 + ")(" + x2 + "," + y2 + ")");
			x1 = event.getX();
			y1 = event.getY();
		}
		if (event.getAction() == MotionEvent.ACTION_UP) {
			// 当手指离开的时候
			x2 = event.getX();
			y2 = event.getY();
			float dx =x1-x2;
			float dy = y1-y2;
			Log.d("geshidsjk", "x1="+x1+"x2="+x2+"y1="+y1+"y2="+y2+"dx="+dx+"dy="+dy);
			if (y1 - y2 > 200) {
				Log.d("zuobiao", "shang");
				issh.isshow = true;
				EventBus.getDefault().post(issh);
				Log.d("geshidsjk", "meizou1");
				return super.dispatchTouchEvent(event);
			} else if (y2 - y1 > 400) {
				Log.d("zuobiao", "xia");
				issh.isshow = false;
				EventBus.getDefault().post(issh);
				Log.d("geshidsjk", "meizou2");
				return super.dispatchTouchEvent(event);
			}

		}
		return super.dispatchTouchEvent(event);
	}

	@Override
	public void register() {
		EventEngine.register(this);
	}

	@Override
	public void unRegister() {
		EventEngine.uregister(this);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		unRegister();
	}
}
